//
//  RequestModel.m
//  ChengHuiTong
//
//  Created by ypwl on 15/11/5.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "RequestModel.h"
#import "AFNetworking.h"
#import "YPShareAccountInfo.h"


#import "BaseNavigationController.h"

#import "YPLogonViewController.h"


#import "MainTabbarViewController.h"
//#define mytoken @"564a82d983723"
#define mytoken [YPShareAccountInfo shareAccountInfo].token
@implementation RequestModel

#pragma mark -- 首页数据

+(void)getRecommendDatasuccessBlock : ( void (^) (id obj) ) successBlock
                          failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[NSString stringWithFormat:@"%@index.php?m=app&c=borrow&a=recommend",kAppHostAddress];
    
    
   
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    manager.securityPolicy.allowInvalidCertificates = YES;
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manager.requestSerializer.timeoutInterval = 10;
//    manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
//    NSCachedURLResponse *cacheResponse =  [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
//    // 拿到缓存的数据
//    data = cacheResponse.data;
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
          successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
         failBlock(error);
        
    }];

   
    
}
#pragma mark 我的资产

+(void)getMyAccountsuccessBlock : ( void (^) (id obj) ) successBlock
                      failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[NSString stringWithFormat:@"%@index.php?m=app&c=account&a=myAccount&token=%@",kAppHostAddress,mytoken];
    
    
   
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSLog(@"我的资产URL--%@",url);
        
        if ([responseObject[@"status"] intValue]==1202) {
            
            if ([YPShareAccountInfo shareAccountInfo].token.length>0) {
                
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CoreLockPWDKey"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [YPShareAccountInfo shareAccountInfo].g_password=nil;
                
                
                [YPShareAccountInfo shareAccountInfo].token=nil;
                
                [[YPShareAccountInfo shareAccountInfo] saveData];
                
                YPLogonViewController*loginViewVC=[[YPLogonViewController alloc] init];
                
                BaseNavigationController*nav=[[BaseNavigationController alloc] initWithRootViewController:loginViewVC];
                
                UIWindow*window=[UIApplication sharedApplication].keyWindow;
                
                MainTabbarViewController*tabbar=(MainTabbarViewController*)window.rootViewController;
                
                [tabbar presentViewController:nav animated:YES completion:nil];
                
                
                
                
                UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"你的账号已在其他设备登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                
                [alert show];
                
            }
        }
        
        
        successBlock(responseObject);
        
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        failBlock(error);

        
    }];
    
}



#pragma mark  账户详情
+(void)getaccountDetailsWtihPage:(NSInteger)page SuccessBlock : ( void (^) (id obj) ) successBlock
                                                    failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[NSString stringWithFormat:@"%@index.php?m=app&c=account&a=accountDetails&token=%@&page=%ld",kAppHostAddress,mytoken,(long)page];
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject)  {
        
        NSLog(@"账户详情URL--%@",url);
        
        if ([responseObject[@"status"] intValue]==1202) {
            
            if ([YPShareAccountInfo shareAccountInfo].token.length>0) {
                
                
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CoreLockPWDKey"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [YPShareAccountInfo shareAccountInfo].g_password=nil;

                
                [YPShareAccountInfo shareAccountInfo].token=nil;
                
                [[YPShareAccountInfo shareAccountInfo] saveData];
                
                YPLogonViewController*loginViewVC=[[YPLogonViewController alloc] init];
                
                BaseNavigationController*nav=[[BaseNavigationController alloc] initWithRootViewController:loginViewVC];
                
                UIWindow*window=[UIApplication sharedApplication].keyWindow;
                
                MainTabbarViewController*tabbar=(MainTabbarViewController*)window.rootViewController;
                
                [tabbar presentViewController:nav animated:YES completion:nil];
                
                
                
                
                UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"你的账号已在其他设备登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                
                [alert show];
                
            }
            
        }

        
        successBlock(responseObject);
        
    }  failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error)
     {
         
         
         
         
         failBlock(error);
     }];
    
}


#pragma mark  回款计划

+(void)getmyReturnPlanWtihPage:(NSInteger)page option:(NSInteger)option View:(UIViewController*)Controller SuccessBlock : ( void (^) (id obj) ) successBlock
                      failBlock : ( void (^) (id obj) ) failBlock{
    
    
    //[MBProgressHUD showHUDAddedTo:Controller.view animated:YES];
    
    NSString *url=[NSString stringWithFormat:@"%@index.php?m=app&c=tender&a=myReturnDetail&token=%@&option=%ld&page=%ld",kAppHostAddress,mytoken,(long)option,(long)page];
    
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSLog(@"回款明细URL--%@",url);
        
        if ([responseObject[@"status"] intValue]==1202) {
            
            if ([YPShareAccountInfo shareAccountInfo].token.length>0) {
                
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CoreLockPWDKey"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [YPShareAccountInfo shareAccountInfo].g_password=nil;

                
                [YPShareAccountInfo shareAccountInfo].token=nil;
                
                [[YPShareAccountInfo shareAccountInfo] saveData];
                
                YPLogonViewController*loginViewVC=[[YPLogonViewController alloc] init];
                
                BaseNavigationController*nav=[[BaseNavigationController alloc] initWithRootViewController:loginViewVC];
                
                UIWindow*window=[UIApplication sharedApplication].keyWindow;
                
                MainTabbarViewController*tabbar=(MainTabbarViewController*)window.rootViewController;
                
                [tabbar presentViewController:nav animated:YES completion:nil];
                
                
                
                
                UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"你的账号已在其他设备登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                
                [alert show];
                
            }
            
        }

        
       // [MBProgressHUD hideAllHUDsForView:Controller.view animated:YES];
        
        successBlock(responseObject);
    
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        
        failBlock(error);
    }];
    
}


#pragma mark  投资记录

+(void)gettenderRecordWtihPage:(NSInteger)page option:(NSInteger)option SuccessBlock : ( void (^) (id obj) ) successBlock
                    failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[NSString stringWithFormat:@"%@index.php?m=app&c=tender&a=tenderRecord&token=%@&option=%ld&page=%ld",kAppHostAddress,mytoken,(long)option,(long)page];
    
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSLog(@"投资记录URL--%@",url);
        if ([responseObject[@"status"] intValue]==1202) {
            
            if ([YPShareAccountInfo shareAccountInfo].token.length>0) {
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CoreLockPWDKey"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];

                [YPShareAccountInfo shareAccountInfo].g_password=nil;
                
                [YPShareAccountInfo shareAccountInfo].token=nil;
                
                [[YPShareAccountInfo shareAccountInfo] saveData];
                
                YPLogonViewController*loginViewVC=[[YPLogonViewController alloc] init];
                
                BaseNavigationController*nav=[[BaseNavigationController alloc] initWithRootViewController:loginViewVC];
                
                UIWindow*window=[UIApplication sharedApplication].keyWindow;
                
                MainTabbarViewController*tabbar=(MainTabbarViewController*)window.rootViewController;
                
                [tabbar presentViewController:nav animated:YES completion:nil];
                
                
                
                
                UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"你的账号已在其他设备登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                
                [alert show];

            }
            
            
        }

        
        successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        failBlock(error);
    }];
    
}


#pragma mark  投资记录搜索

+(void)searchTenderWithTitle:(NSString*)title SuccessBlock : ( void (^) (id obj) ) successBlock
                    failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[[NSString stringWithFormat:@"%@index.php?m=app&c=tender&a=searchTender&token=%@&title=%@",kAppHostAddress,mytoken,title] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSLog(@"投资记录搜索URL--%@",url);
        if ([responseObject[@"status"] intValue]==1202) {
            
            if ([YPShareAccountInfo shareAccountInfo].token.length>0) {
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CoreLockPWDKey"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [YPShareAccountInfo shareAccountInfo].token=nil;
                
                [[YPShareAccountInfo shareAccountInfo] saveData];
                
                YPLogonViewController*loginViewVC=[[YPLogonViewController alloc] init];
                
                BaseNavigationController*nav=[[BaseNavigationController alloc] initWithRootViewController:loginViewVC];
                
                UIWindow*window=[UIApplication sharedApplication].keyWindow;
                
                MainTabbarViewController*tabbar=(MainTabbarViewController*)window.rootViewController;
                
                [tabbar presentViewController:nav animated:YES completion:nil];
                
                
                
                
                UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"你的账号已在其他设备登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                
                [alert show];
                
            }
        }

        
        successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        failBlock(error);
        
    }];
    
}


#pragma mark  发送手机验证码（设置交易密码）

+(void)sendCodeWithPhone:(NSString*)phone SuccessBlock : ( void (^) (id obj) ) successBlock
                  failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[[NSString stringWithFormat:@"%@index.php?m=app&c=user&a=sendPayCode&token=%@&phone=%@",kAppHostAddress,mytoken,phone] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject){
        
        NSLog(@"投资记录搜索URL--%@",url);
        
        
        successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        failBlock(error);
        
    }];
    
}


#pragma mark  设置交易密码

+(void)sendCodeWithPassword:(NSString*)password code:(NSString*)code smsid:(NSString*)smsid SuccessBlock : ( void (^) (id obj) ) successBlock
              failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[[NSString stringWithFormat:@"%@index.php?m=app&c=user&a=paypass",kAppHostAddress] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",mytoken] dataUsingEncoding:NSUTF8StringEncoding] name:@"token"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",password] dataUsingEncoding:NSUTF8StringEncoding] name:@"paypass"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",smsid] dataUsingEncoding:NSUTF8StringEncoding] name:@"smsid"];
        
        [formData appendPartWithFormData:[@"1" dataUsingEncoding:NSUTF8StringEncoding] name:@"encrypt"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",code] dataUsingEncoding:NSUTF8StringEncoding] name:@"code"];

        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        failBlock(error);
    }];
    
       
}


+(void)getBaseUrlSuccessBlock : ( void (^) (id obj) ) successBlock
                    failBlock : ( void (^) (id obj) ) failBlock{
    
     NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    NSString *url=[[NSString stringWithFormat:@"%@?version=%@&os_type=1",CMD_GET_URL,version] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@""]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failBlock(error);
    }];
    
    
   
    
}

+(void)LogOutSuccessBlock : ( void (^) (id obj) ) successBlock
                    failBlock : ( void (^) (id obj) ) failBlock{
    
   // NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    NSString *url=[[NSString stringWithFormat:@"%@index.php?m=app&c=user&a=logout&token=%@",kAppHostAddress,mytoken] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject){
        
        
        
        successBlock(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        failBlock(error);
        
    }];
    
    
}

+(void)loginSuccessWithname:(NSString*)name andPwd:(NSString*)pwd Block : ( void (^) (id obj) ) successBlock
               failBlock : ( void (^) (id obj) ) failBlock{
    
    NSString *url=[CMD_LOGIN stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    /*
     username
     password
     app_type
     encrypt;*/
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",name] dataUsingEncoding:NSUTF8StringEncoding] name:@"username"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",pwd] dataUsingEncoding:NSUTF8StringEncoding] name:@"password"];
        
        [formData appendPartWithFormData:[@"1" dataUsingEncoding:NSUTF8StringEncoding] name:@"encrypt"];
        
        [formData appendPartWithFormData:[@"1" dataUsingEncoding:NSUTF8StringEncoding] name:@"app_type"];
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        successBlock(responseObject);

        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        failBlock(error);
    }];
    
    
}

+(void)RegisterSuccessWithname:(NSString*)name andPwd:(NSString*)pwd phone:(NSString*)phone code:(NSString*)code smsid:(NSString*)smsid  Block : ( void (^) (id obj) ) successBlock
                 failBlock : ( void (^) (id obj) ) failBlock{
    
    // NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    NSString *url=[CMD_REGIST stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        
        
        [formData appendPartWithFormData:[ [NSString stringWithFormat:@"%@",name] dataUsingEncoding:NSUTF8StringEncoding] name:@"username"];
        
        NSLog(@"用户名%@",name);
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",pwd] dataUsingEncoding:NSUTF8StringEncoding] name:@"password"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",code] dataUsingEncoding:NSUTF8StringEncoding] name:@"code"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",smsid] dataUsingEncoding:NSUTF8StringEncoding] name:@"smsid"];
        
        [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",phone] dataUsingEncoding:NSUTF8StringEncoding] name:@"phone"];
        
        [formData appendPartWithFormData:[@"1" dataUsingEncoding:NSUTF8StringEncoding] name:@"encrypt"];
        
        [formData appendPartWithFormData:[@"1" dataUsingEncoding:NSUTF8StringEncoding] name:@"app_type"];
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        failBlock(error);

    }];
    
    
}



+(void)POSTWithURRL:(NSString*)urlString andDic:(NSDictionary*)dic Block : ( void (^) (id obj) ) successBlock
         failBlock : ( void (^) (id obj) ) failBlock{
    
    // NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    NSString *url=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kAppHostAddress]];
    
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
   
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        NSArray*keys=[dic allKeys];
        
        for (int i=0; i<keys.count; i++) {
            
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",dic[keys[i]]] dataUsingEncoding:NSUTF8StringEncoding] name:[NSString stringWithFormat:@"%@",keys[i]]];
        }

        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
         successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
          failBlock(error);
    }];
    
    
   
    
}


@end

